﻿using BonjourQuotation.DataAccess.Repositories;
using BonjourQuotation.ObjectModel.AccountData;
using BonjourQuotation.ObjectModel.ErrorData;
using BonjourQuotation.ObjectModel.LoggerData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BonjourQuotation.UI.ServiceManagers
{
    public class AccountManager
    {
        private readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public LoginResponseData Login(LoginRequestData UserData)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.Login(UserData);
            }
            catch(Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public CreateUserResponseData CreateUser(CreateUserRequestData UserData)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.CreateUser(UserData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
            
        }
        public ErrorBInfo PostUserDetailsData(UserDetailsBData UserData)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.PostUserDetailsData(UserData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ErrorBInfo SaveProfileData(string UserName, int ProfileID, string ProfileName)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.SaveProfileData(UserName, ProfileID, ProfileName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public string GetUserName(int UserID)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.GetUserName(UserID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public List<ManageUsersGridBData> ManageUsers()
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.GetAllUsers();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public UserDetailsBData GetUserDetails(int EmployeeID)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.GetUserDetailsByEmpID(EmployeeID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ErrorBInfo DeleteUserByIdUsers(int UserId)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.DeleteUserById(UserId);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public EditUserBData GetEditUserData(int UserId)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.GetEditUserData(UserId);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ErrorBInfo PostEditUserData(EditUserBData UserData)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.PostEditUserData(UserData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ToolBData LoadTools()
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.LoadTools();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ProfileBData LoadProfiles(string UserName)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.LoadProfiles(UserName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ToolBData LoadToolTab(int ToolID)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.LoadToolTab(ToolID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ToolTabColumnPermisionsCanViewCanEditHasFilterGridBData LoadToolTabColumnPermissionsCanViewCanEditHasFilter(int UserID, int ToolTabID)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.LoadToolTabColumnPermissionsCanViewCanEditHasFilter(UserID, ToolTabID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ToolTabColumnPermisionsCanViewGridBData LoadToolTabColumnPermissionsCanView(int UserID, int ToolTabID)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.LoadToolTabColumnPermissionsCanView(UserID, ToolTabID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ToolTabColumnPermisionsCanViewCanEditGridBData LoadToolTabColumnPermissionsCanViewCanEdit(int UserID, int ToolTabID)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.LoadToolTabColumnPermissionsCanViewCanEdit(UserID, ToolTabID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ToolTabColumnPermisionsCanViewCanEditHasFilterGridBData LoadProfileToolTabColumnPermissionsCanViewCanEditHasFilter(string UserName, string ProfileName, int ProfileID, int ToolTabID)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.LoadProfileToolTabColumnPermissionsCanViewCanEditHasFilter(UserName, ProfileName, ProfileID, ToolTabID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ToolTabColumnPermisionsCanViewGridBData LoadProfileToolTabColumnPermissionsCanView(string UserName, string ProfileName, int ProfileID, int ToolTabID)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.LoadProfileToolTabColumnPermissionsCanView(UserName, ProfileName, ProfileID, ToolTabID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ToolTabColumnPermisionsCanViewCanEditGridBData LoadProfileToolTabColumnPermissionsCanViewCanEdit(string UserName, string ProfileName, int ProfileID, int ToolTabID)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.LoadProfileToolTabColumnPermissionsCanViewCanEdit(UserName, ProfileName, ProfileID, ToolTabID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ErrorBInfo SaveToolTabColumnPermissionsCanViewCanEditHasFilter(ToolTabColumnPermisionsCanViewCanEditHasFilterGridBData Data, string UserName)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.SaveToolTabColumnPermissionsCanViewCanEditHasFilter(Data, UserName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ErrorBInfo SaveToolTabColumnPermissionsCanView(ToolTabColumnPermisionsCanViewGridBData Data, string UserName)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.SaveToolTabColumnPermissionsCanView(Data, UserName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ErrorBInfo SaveToolTabColumnPermissionsCanViewCanEdit(ToolTabColumnPermisionsCanViewCanEditGridBData Data, string UserName)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.SaveToolTabColumnPermissionsCanViewCanEdit(Data, UserName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public ErrorBInfo ApplyProfileToUser(int UserID, int ProfileID)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.ApplyProfileToUser(UserID, ProfileID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public Dictionary<string, string> LoadState()
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.LoadState();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
        public Dictionary<int, string> LoadCity(int CountryID, string StateID)
        {
            try
            {
                var proxy = new AccountRepository();
                return proxy.LoadCity(CountryID, StateID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            } 
        }
    }
}